<?php
namespace app\app\controller\v1;
use app\app\Appbase;
//
//地址模块
//
class Address extends Appbase 
{
	/**
	* 获取地址列表
	* /app/v1/address/getAddressList
	* 需要登录 
	* @is_need_login true
	* @method all
	*/
	public function getAddressList(){
		try {
			$result = model('UserAddress')->getAddressList( request() ->userId );
			return $this->ReSucess($result);	
		} catch (\Exception $e) {
			return $this->ReError($e->getMessage());	
		}
	}
	
	/**
	*添加地址
	* /app/v1/Address/addAddress
	* 需要登录 
	* @is_need_login true
	* @method post
	*/
	public function addAddress(){
		$data =  request()->post();
		$uid = $data['uid']  = request() ->userId;
		try {
			$address = model('UserAddress');
			if ( !$address->addAddress($data) ) {
	           return $this->ReError( $address ->errorInfo );
	        }
			return $this->ReSucess();	
		} catch (\Exception $e) {
			return $this->ReError($e->getMessage());	
		}
	}
	
	/**
	*编辑地址
	* /app/v1/Address/editAddress
	* 需要登录 
	* @is_need_login true
	* @method post
	*/
	public function editAddress($id){
		if(!$id){
			return $this->ReError("参数错误！");	
		}
		$data =  request()->post();
		$uid = $data['uid']  = request() ->userId;
		try {
			$address = model('UserAddress');
			if ( !$address->editAddress($id,$data) ) {
	           return $this->ReError( $address ->errorInfo );
	        }
			return $this->ReSucess();	
		} catch (\Exception $e) {
			return $this->ReError($e->getMessage());	
		}
	}

	/**
	* 删除地址
	* /app/v1/Address/delAddress
	* 需要登录 
	* @is_need_login true
	* @method post
	*/
	public function delAddress($ids){
		$uid = $data['uid']  = request() ->userId;
		if(!$ids){
			return $this->ReError("参数错误！");	
		}
		try {
			$address = model('UserAddress');
			if ( !$address->delAddress($uid,$ids) ) {
	           return $this->ReError( $address ->errorInfo );
	        }
			return $this->ReSucess();	
		} catch (\Exception $e) {
			return $this->ReError($e->getMessage());	
		}
	}
	
	/**
	* 设置默认地址
	* /app/v1/Address/delAddress
	* 需要登录 
	* @is_need_login true
	* @method post
	*/
	public function defaultAddress($id){
		$uid = $data['uid']  = request() ->userId;
		if(!$id){
			return $this->ReError("参数错误！");	
		}
		try {
			$address = model('UserAddress');
			if ( !$address->defaultAddress($uid,$id) ) {
	           return $this->ReError( $address ->errorInfo );
	        }
			return $this->ReSucess();	
		} catch (\Exception $e) {
			return $this->ReError($e->getMessage());	
		}
	}
	
	
}



